/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Classes {
    public static boolean insertClass(Entity.Class cls)
    {
        try {
            String sql = "insert into tblClass values (?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, cls.get_ClassID());
            ps.setString(2, cls.get_ClassName());
            ps.setString(3, cls.get_CoursesID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Classes.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateClass(Entity.Class cls)
    {
        try {
            String sql = "update tblClass set ClassName=?, CoursesID=? where ClassID = ?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, cls.get_ClassName());
            ps.setString(2, cls.get_CoursesID());
            ps.setString(3, cls.get_ClassID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Classes.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static void deleteClass(String ClassID)
    {
        try {
            String sql = "delete from tblClass where ClassID = '" + ClassID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Classes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
